<?php 
	$username = $_SESSION['username'];    $query = "select * from user where username='$username'";    $result = mysql_query($query);
	$user = mysql_fetch_array($result);
?>
<table height="320px" width="603px">
				<tr><td id="info" valign="top">
					<table cellpadding="0" cellspacing="0" >
						<tr><td width="395px" valign="top">
						<?php include 'navbar.php'; ?>
						</td>
						<td>&nbsp;</td>
						<td valign="top">
							<table cellpadding="0" cellspacing="0" border="0" align="right" width="185px"><tr><td><?php include 'usergreet.php'; ?>
							</td></tr><tr><td id="login"><div align="right"><span style="font-size:12px"><? echo $user['nick']; ?></span> ( <strong><a href="index.php?act=logout">Logout</a></strong> )</div></td></tr></table>
					

						</td></tr>
					</table>

					<table cellpadding="0" cellspacing="0"><tr><td width="385px" valign="top">
					<div align="left"><h3>Enter 12-Digit Friend Code</h3>
						<span style="font-size:8pt">To enable matchmaking...
						<p /><?php 					
									if (!isset($_POST['submit'])) {     									include 'gamecode_form.inc.php';									}
else							{

								if (!is_numeric ($_POST['gamecode']) || strlen($_POST['gamecode']) != 12 || empty($_POST['gamecode']))								{									$gamecode_error = 'Your Friend Code is invalid...';
									$error = '1';          							include 'gamecode_form.inc.php';								}

								$gamecode = $_POST['gamecode'];								$checkuser = mysql_query("SELECT gamecode FROM user WHERE gamecode='$gamecode'");								$gamecode_exist = mysql_num_rows($checkuser);								if($gamecode_exist > 0 && $gamecode != '' && $error=='0')
								{   							    	$gamecode_error = "Friend Code is currently used";
									$error = '1';									include 'gamecode_form.inc.php';								}	
								if (empty($gamecode_error)) {								mysql_query("UPDATE user SET gamecode = '$gamecode' WHERE username='$username'");
								echo 'Thanks and enjoy playing here...';} else {$error='0'; $gamecode_error='';}							}
							 ?></span></td><td valign="top">
						<?php include 'sidebar.php' ?>					
					</td>

					</tr></table>
				
					</td></tr>
			</table>
			</td>
		</tr>
	</table>

<?php include 'footer.php' ?>
